package fr.labri.macchiato.core.model;

import java.util.ArrayList;
import java.util.List;

import fr.labri.macchiato.core.api.Finder;
import fr.labri.macchiato.core.model.utils.Address;
import fr.labri.macchiato.core.model.utils.TimeSlot;
import fr.labri.macchiato.core.technical.Identifiable;

/**
 * Class regrouping the user's preferences, such as his address, whether to use
 * localStorage or sessionStorage, etc...
 * 
 * @author Matthieu FOUCAULT
 * @author Michelle AVOMO
 * 
 */
public class UserPreferences implements Identifiable<String> {

	/**
	 * The id of the UserPreferences object
	 */
	public static final String PREFS_ID = "prefs";

	private Address homeAddress;
	private Address workAddress;

	private List<TimeSlot> shoppingHours;
	private List<BusinessEntity> favoriteBusinessEntities;

	private List<Finder> favoriteFinders;
	
	public List<Finder> getFavoriteFinders() {
		return favoriteFinders;
	}

	public void setFavoriteFinders(List<Finder> favoriteFinders) {
		this.favoriteFinders = favoriteFinders;
	}

	private boolean  useLocalStorage;

	private boolean preferencesConfigured;

	/**
	 * Creates a new UserPreferences with the default values
	 */
	public UserPreferences() {
		homeAddress = new Address();
		workAddress = new Address();

//		preferencesOrder = new ArrayList<PreferenceKind>();
		setDefaultPreferencesOrder();
		
		favoriteBusinessEntities = new ArrayList<BusinessEntity>();

		favoriteFinders = new ArrayList<Finder>();
		
		preferencesConfigured = false;
		useLocalStorage = false;

	}

	/**
	 * 
	 * @return the user's favorite providers
	 */
	public List<BusinessEntity> getFavoriteBusinessEntities() {
		return favoriteBusinessEntities;
	}

	/**
	 * 
	 * @return the user's home address
	 */
	public Address getHomeAddress() {
		return homeAddress;
	}

	public String getId() {
		return PREFS_ID;
	}

	/**
	 * 
	 * @return true if the preferences have been configured, false otherwise
	 */
	public boolean getPreferencesConfigured() {
		return preferencesConfigured;
	}

	/**
	 * Set to true if the preferences have been configured
	 * 
	 * @param preferencesConfigured
	 */
	public void setPreferencesConfigured(boolean preferencesConfigured) {
		this.preferencesConfigured = preferencesConfigured;
	}

	/**
	 * @return the user's preferences order
	 */
//	public List<PreferenceKind> getPreferencesOrder() {
//		return preferencesOrder;
//	}

	/**
	 * @return true if we use local storage, false otherwise
	 */
	public boolean getUseLocalStorage() {
		return useLocalStorage;
	}

	/**
	 * 
	 * @return the user's work address
	 */
	public Address getWorkAddress() {
		return workAddress;
	}

	/**
	 * Sets the user's work address
	 * 
	 * @param workAddress
	 */
	public void setWorkAddress(Address workAddress) {
		this.workAddress = workAddress;

	}

	private void setDefaultPreferencesOrder() {
//		preferencesOrder.add(PreferenceKind.PRICE);
//		preferencesOrder.add(PreferenceKind.DISTANCE);
//		preferencesOrder.add(PreferenceKind.BUSINESS_ENTITY);
	}

	/**
	 * sets the user's favorite providers
	 * 
	 * @param favoriteProviders
	 */
	public void setFavoriteBusinessEntities(List<BusinessEntity> favoriteProviders) {
		this.favoriteBusinessEntities = favoriteProviders;
	}

	/**
	 * Sets the user's home address
	 * 
	 * @param homeAddress
	 */
	public void setHomeAddress(Address homeAddress) {
		this.homeAddress = homeAddress;
	}

	/**
	 * 
	 * @param preferencesOrder
	 */
//	public void setPreferencesOrder(List<PreferenceKind> preferencesOrder) {
//		this.preferencesOrder = preferencesOrder;
//	}

	/**
	 * @return the shoppingHours
	 */
	public List<TimeSlot> getShoppingHours() {
		return shoppingHours;
	}

	/**
	 * @param shoppingHours the shoppingHours to set
	 */
	public void setShoppingHours(List<TimeSlot> shoppingHours) {
		this.shoppingHours = shoppingHours;
	}

	/**
	 * @param useLocalStorage the useLocalStorage to set
	 */
	public void setUseLocalStorage(boolean useLocalStorage) {
		this.useLocalStorage = useLocalStorage;
	}

	@Override
	public boolean equals(Object object) {
		if (!(object instanceof UserPreferences))
			return false;
		
		UserPreferences prefs = (UserPreferences)object;
		
		return (prefs.getHomeAddress().equals(getHomeAddress())) && (prefs.getWorkAddress().equals(getWorkAddress()));
	}
}
